package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"path"
	"path/filepath"
	"regexp"
)

func checkMultipath(path string) bool {
	multipathStatus := true
	err := filepath.Walk(path, func(path string, f os.FileInfo, err error) error {
		if f == nil {
			return err
		}
		if f.IsDir() {
			reg, err := regexp.Compile("^.*host.*session.*target.*")
			if err != nil {
				fmt.Println(err)
				return err
			}
			multipathStatus = reg.MatchString(path)
		}
		return nil
	})
	if err != nil {
		return false
	}
	return multipathStatus
}

func main() {
	dirPath := "E:/application/go_learning/multipath/"

	regHost, err := regexp.Compile("^.*host.*")
	if err != nil {
		fmt.Println(err)
		return
	}

	files, err := ioutil.ReadDir(dirPath)
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, file := range files {
		matched := regHost.MatchString(path.Join(dirPath, file.Name()))
		if file.IsDir() && matched {
			status := checkMultipath(path.Join(dirPath, file.Name()))
			if status {
				fmt.Println(path.Join(dirPath, file.Name()) + ": 路径正常")
			} else {
				fmt.Println(path.Join(dirPath, file.Name()) + ": 路径异常")
			}
		}

	}

}
